/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Training;

import weka.core.Instances;
import weka.filters.unsupervised.attribute.MathExpression;
import weka.filters.unsupervised.attribute.NumericToNominal;

/**
 *
 * @author fabio
 */
public class InstancesFilter {

    public Instances filterInstances(Instances instances) throws Exception {
        //Remove mailid
        instances.deleteAttributeAt(0);

        //SetClassIndex(spam)
        int classSpam = instances.numAttributes() - 1;
        instances.setClassIndex(classSpam);

        // CapsAvg 1:[0,20] 2:]20,40] 3:]40,60] 4:]60,80] 5:]80,100]
        MathExpression me = new MathExpression();
        me.setExpression("ifelse(A>20, ifelse(A>80, 5, ifelse(A>60,4,ifelse(A<=40,2,3))),1)");
        me.setIgnoreRange("10");
        me.setInvertSelection(true);
        me.setIgnoreClass(true);
        me.setInputFormat(instances);
        instances = weka.filters.Filter.useFilter(instances, me);

        //NumericToNominal
        //int sentHour  = insts.
        NumericToNominal ntn = new NumericToNominal();
        int[] atribNtn = {classSpam, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}; //Spam //@TODO horas CapsAv SentHourg
        ntn.setAttributeIndicesArray(atribNtn);
        ntn.setInputFormat(instances);
        instances = weka.filters.Filter.useFilter(instances, ntn);

        return instances;
    }
}
